c++11 containers | |
---|---|
sorted_vector | use when doing lots of unsorted insertions and maintaining constant sort would be expensive |
map | sorted binary search tree; always sorted by key; you can walk through in sorted order |
multimap | same as map but allows dupe keys; need for this should be pretty rare |
unordered_map | hashmap; always sorted by key; additional bucket required for hash collisions; no defined order when walking through |
unordered_multimap | same as map but allows dupe keys; dupes are obviously in the same bucket, and you can walk just the dupes if needed |
set multiset unordered_set unordered_multiset |
sets are just like maps, except the key is embedded in the object, great idea but… they are ruined by the constraint that contained items must be const but… then redeemed by mutable You can use mutable on the variable that are not part of the key to remove the const! This changes the constness of the object from binary (completely const) to logical (constness is defined by the developer) so… set is an excellent way to achieve both encapsulation and logical const Final note: using object pointers is the ultimate solution. |